using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextDialog : MonoBehaviour
{
	private static string path = "UI/TextDialog";

	private static List<TextDialog> m_DialogsList = new List<TextDialog>();

	private Animator m_Animator;

	private Delegate0Args m_SureCallBack;

	private Delegate0Args m_CancelCallback;

	[SerializeField]
	private GameObject m_Button1;

	[SerializeField]
	private GameObject m_Button2;

	[SerializeField]
	private Text m_Text;

	public static List<TextDialog> DialogsList => m_DialogsList;

	private void Awake()
	{
		m_Animator = GetComponent<Animator>();
		m_Animator.SetTrigger("Show");
		base.name = "TextDialog";
		DialogsList.Add(this);
	}

	private void OnEnable()
	{
		if ((bool)BaseUIController.Instance && !BaseUIController.Instance.menuHide)
		{
			BaseUIController.Instance.OnMenuButtonClick();
		}
	}

	private void Hide()
	{
		DialogsList.Remove(this);
		m_Animator.SetTrigger("Hide");
	}

	public void OnClick()
	{
		Hide();
		if (m_SureCallBack != null)
		{
			m_SureCallBack();
		}
	}

	public void OnCancel()
	{
		Hide();
		if (m_CancelCallback != null)
		{
			m_CancelCallback();
		}
	}

	private void _Show(string text)
	{
		m_Text.text = text;
		m_Button1.SetActive(value: true);
		m_Button2.SetActive(value: false);
	}

	private void _Show2Button(string text)
	{
		m_Text.text = text;
		m_Button1.SetActive(value: false);
		m_Button2.SetActive(value: true);
	}

	public void SetButtonText(int id, int btnIndex)
	{
		SetButtonText(HOLocalizationConfiguration.GetValue(id), btnIndex);
	}

	public void SetButtonText(string text, int btnIndex)
	{
		if (m_Button1.activeInHierarchy && btnIndex == 1)
		{
			Text componentInChildren = m_Button1.transform.GetChild(0).GetComponentInChildren<Text>();
			componentInChildren.text = text;
			UnityEngine.Object.Destroy(componentInChildren.GetComponent<TextID>());
			return;
		}
		switch (btnIndex)
		{
		case 1:
		{
			Text componentInChildren3 = m_Button2.transform.GetChild(0).GetComponentInChildren<Text>();
			componentInChildren3.text = text;
			UnityEngine.Object.Destroy(componentInChildren3.GetComponent<TextID>());
			break;
		}
		case 2:
		{
			Text componentInChildren2 = m_Button2.transform.GetChild(1).GetComponentInChildren<Text>();
			componentInChildren2.text = text;
			UnityEngine.Object.Destroy(componentInChildren2.GetComponent<TextID>());
			break;
		}
		}
	}

	public static void Show(string text, Delegate0Args callback = null)
	{
		UIADViewWnd.ShowTip(text, callback);
	}

	public static void Show(int id, Delegate0Args callback = null)
	{
		Show(HOLocalizationConfiguration.GetValue(id), callback);
	}

	public static void Show2Button(string text, Delegate0Args sureCallback, Delegate0Args cancelCallback = null, bool bShowIcon = false)
	{
		UIADViewWnd.ShowTip(text, sureCallback, cancelCallback, bShowIcon);
	}

	public static void Show2Button(int id, Delegate0Args sureCallback, Delegate0Args cancelCallback = null)
	{
		Show2Button(HOLocalizationConfiguration.GetValue(id), sureCallback, cancelCallback);
	}
}
